package ch.zbw.swt.sysventory.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;

import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import IMG.GetPath;

/*
 * GUI um den Scanvorgang zu starten
 */

public class GUIScannen extends JFrame{
	
	//Panels
	private JPanel panel;
	
	//Bilder
	private ImageIcon goArrow;
	private ImageIcon backArrow;
	
	//Labels
	private JLabel menuTitelLabel;
	private JLabel vonIPLabel;
	private JLabel bisIPLabel;
	private JLabel infoEinzelIPLabel;
	
	//Buttons
	private JButton go2ScanButton;
	private JButton back2MenuButton;
	
	//Texfeld
	private JTextField startIPtxtField;
	private JTextField endIPtxtField;

	//Listener
	private Action action;

	
	/**
	 * Konstruktur von GUI
	 */
	public GUIScannen(Action action) {
		this.action = action;
	}
	
	/**
	 * Initialisierung von GUI
	 */
	public void initialize(String startIp, String endIp) {
		
		//Eingenschaften von GUI
		this.getContentPane().setBackground(Color.WHITE);
		this.setBackground(Color.WHITE);
		this.setBounds(100, 100, 770, 480);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.getContentPane().setLayout(null);
		
		
		//Einmittung
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		int top = (screenSize.height - this.getHeight()) / 2;
		int left = (screenSize.width - this.getWidth()) / 2;
		this.setLocation(left, top);
		
		//weitere Eigenschaften
		this.setResizable(false);
		this.setVisible(true);
		
		//Einfügen der Elemente
		panel = new JPanel();
		panel.setBackground(Color.WHITE);
		panel.setBounds(10, 11, 744, 83);
		this.getContentPane().add(panel);
		panel.setLayout(null);
		
				
		goArrow = new ImageIcon(GetPath.class.getResource("go.png"));			
		backArrow = new ImageIcon(GetPath.class.getResource("back.png"));
		
		menuTitelLabel = new JLabel("Scannen");
		menuTitelLabel.setFont(new Font("Impact", Font.PLAIN, 36));
		menuTitelLabel.setBounds(307, 11, 209, 61);
		panel.add(menuTitelLabel);
		
		go2ScanButton = new JButton(goArrow);
		go2ScanButton.setBackground(Color.WHITE);
		go2ScanButton.setBounds(592, 11, 129, 61);
		go2ScanButton.setBorder(null);
		panel.add(go2ScanButton);
		
		back2MenuButton = new JButton(backArrow);
		back2MenuButton.setBounds(24, 11, 129, 61);
		back2MenuButton.setBorder(null);
		panel.add(back2MenuButton);
		
		startIPtxtField = new JTextField();
		startIPtxtField.setFont(new Font("Impact", Font.PLAIN, 16));
		startIPtxtField.setText(startIp);
		startIPtxtField.setBounds(195, 241, 160, 39);
		this.getContentPane().add(startIPtxtField);
		startIPtxtField.setColumns(10);
		
		vonIPLabel = new JLabel("IPRange von:");
		vonIPLabel.setFont(new Font("Impact", Font.PLAIN, 16));
		vonIPLabel.setBounds(71, 241, 114, 39);
		this.getContentPane().add(vonIPLabel);
		
		bisIPLabel = new JLabel("bis:");
		bisIPLabel.setFont(new Font("Impact", Font.PLAIN, 16));
		bisIPLabel.setBounds(384, 241, 114, 39);
		this.getContentPane().add(bisIPLabel);
		
		endIPtxtField = new JTextField();
		endIPtxtField.setFont(new Font("Impact", Font.PLAIN, 16));
		endIPtxtField.setText(endIp);
		endIPtxtField.setColumns(10);
		endIPtxtField.setBounds(508, 241, 160, 39);
		this.getContentPane().add(endIPtxtField);
		
		infoEinzelIPLabel = new JLabel("Bei einzelnem IP-Scan von bis gleich identisch");
		infoEinzelIPLabel.setFont(new Font("Arial", Font.PLAIN, 12));
		infoEinzelIPLabel.setBounds(276, 344, 272, 33);
		this.getContentPane().add(infoEinzelIPLabel);
		
		//Actionlistener setzen
		go2ScanButton.addActionListener(action);
		go2ScanButton.setActionCommand("go2Scan");
		back2MenuButton.addActionListener(action);
		back2MenuButton.setActionCommand("back2Menu");
	}
	/*
	 * Liefert die Daten aus den Textfeldern für den Scann zurück.
	 */
	
	//StartIP
	public String getstartip() {
		return startIPtxtField.getText();
	}
	
	//EndIP
	public String getendip() {
		return endIPtxtField.getText();
	}
	
	/*
	 * setzt einen Vorschlagswert bei der Initialsierung
	 * aufgrund von IP-Adresse von Server
	 */
	
	//StartIP
	public void setStartIPtxtField(String startIPtxtField) {
		this.startIPtxtField.setText(startIPtxtField);
	}
	
	//EndIP
	public void setEndIPtxtField(String endIPtxtField) {
		this.endIPtxtField.setText(endIPtxtField);
	}

}